﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataTier;
using BusinessTier;
using System.Threading;
using TestClient.ElectricCarService;

namespace TestClient
{
    class PathFinderTester
    {

        private static List<Location> locations;

        private static void CreateLocations()
        {

            Console.WriteLine("Running PathFinder test");
            Console.WriteLine();

            // Oprettelse af locations
            Location firstLocation = new Location("First");
            Location secondLocation = new Location("Second");
            Location thirdLocation = new Location("Third");
            Location fourthLocation = new Location("Fourth");
            Location fifthLocation = new Location("Fifth");
            Location sixthLocation = new Location("Sixth");

            // Tilføj locations til liste
            locations = new List<Location>();
            locations.Add(firstLocation);
            locations.Add(secondLocation);
            locations.Add(thirdLocation);
            locations.Add(fourthLocation);
            locations.Add(fifthLocation);
            locations.Add(sixthLocation);

            // Oprettelse af connections
            firstLocation.AddConnection(secondLocation, 10);
            firstLocation.AddConnection(fifthLocation, 14);

            secondLocation.AddConnection(firstLocation, 10);
            secondLocation.AddConnection(thirdLocation, 8);

            thirdLocation.AddConnection(secondLocation, 8);
            thirdLocation.AddConnection(fourthLocation, 12);
            thirdLocation.AddConnection(fifthLocation, 15);

            fourthLocation.AddConnection(thirdLocation, 12);
            fourthLocation.AddConnection(fifthLocation, 6);
            fourthLocation.AddConnection(sixthLocation, 10);

            fifthLocation.AddConnection(firstLocation, 14);
            fifthLocation.AddConnection(thirdLocation, 15);
            fifthLocation.AddConnection(fourthLocation, 6);
            fifthLocation.AddConnection(sixthLocation, 11);

            sixthLocation.AddConnection(fourthLocation, 10);
            sixthLocation.AddConnection(fifthLocation, 11);

        }

        public static void RunTest()
        {

            CreateLocations();

            // Oprettelse af path finder
            PathFinder pathFinder = new PathFinder(locations);

            Console.WriteLine("Finding path from first to fourth");
            Console.WriteLine("Expected path: Fifth - Fourth");

            // Find vej fra location 1 til 4
            Route firstToFourth = pathFinder.FindPath(locations[0], locations[3]);
            Console.WriteLine("Found path: " + firstToFourth.ToString());

            Console.WriteLine();
            Console.WriteLine("Finding path from third to sixth");
            Console.WriteLine("Expected path: Fourth - Sixth");

            // Find vej fra location 3 til 6
            Route thirdToSixth = pathFinder.FindPath(locations[2], locations[5]);
            Console.WriteLine("Found path: " + thirdToSixth.ToString());

            Console.WriteLine();
            Console.WriteLine("Finding path from second to fifth");
            Console.WriteLine("Expected path: Third - Fifth");

            // Find vej fra location 2 til 5
            Route secondToFifth = pathFinder.FindPath(locations[1], locations[4]);
            Console.WriteLine("Found path: " + secondToFifth.ToString());

        }

    }
}
